/*
 * Tools.h
 *
 *  Created on: 26.05.2011
 *      Author: sili
 */

#ifndef TOOLS_H_
#define TOOLS_H_

#include <xercesc/dom/DOM.hpp>
#include <xercesc/framework/LocalFileFormatTarget.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/PlatformUtils.hpp>

#include <string>
#include <string.h>

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <iostream>
#include <algorithm>

#include <map>
#include <set>
#include <vector>

using namespace std;
using namespace xercesc;

struct AALLocation {
	double top;
	double left;
};

struct AALSize {
	double width;
	double height;
};

struct AALArea {
	double left;
	double top;
	double width;
	double height;
	AALArea(){
		top = 0;
		left = 0;
		width = 0;
		height = 0;
	}
	AALArea(double _left, double _top, double _width, double _height){
		top = _top;
		left = _left;
		width = _width;
		height = _height;
	}
	void adopt(AALArea * _area){
		top = _area->top;
		left = _area->left;
		width = _area->width;
		height = _area->height;
	}
};

#define MAX_LOG_MESSAGES 100			// max history length (ringbuffer)
#define MAX_LOG_MESSAGE_LEN 1024		// the max length in chars a message or data can have

class Tools{
public:
	static void getStringAttributeValue(DOMNode * _node, const char * _searchKey, string * _buffer);
	static int getIntAttributeValue(DOMNode * _node, const char * _searchKey);
	static double getDoubleAttributeValue(DOMNode * _node, const char * _searchKey);

	static void createSvgTemplateFile(DOMDocument * _doc, DOMNode * _node, const char * _templateFile, int _width, int _height);
	static void createXmlFileFromDOMDocument(const char * _filename, DOMDocument * _doc);
	static DOMDocument * createDOMFromXmlFile(const char * _xmlFilename, XercesDOMParser * _parser);

	static bool renameFile(const char * _oldFileName, const char * _newFileName, string * _response);

	static int getIntFromString(const char * _string) throw(int);
	static double getDoubleFromString(const char * _string) throw(int);

	static void execCmd(char * cmd, string * cmdResult);
	static void split(const char * input, const char * delim, vector<string> * buffer);
	static bool endsWith(const string & _str, const string & _key);

	static void stringCopy(char * dst, const char * src, size_t len);
	static long getNewGlobalId();
};

#endif /* TOOLS_H_ */
